package com.hk;

import java.util.Arrays;
import java.util.Collection;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentNavigableMap;
import java.util.concurrent.ConcurrentSkipListMap;

/**
 * @author: dpb
 * @date: 2022/3/21
 */
public class MapDemo {
    public static void main(String[] args) {
        ConcurrentSkipListMap<Long, String> skipListMap = new ConcurrentSkipListMap<>();

        skipListMap.put(1L,"zs");
        skipListMap.put(2L,"ls");
        skipListMap.put(3L,"ww");
        skipListMap.put(4L,"zl");
        skipListMap.put(5L,"dd");
        skipListMap.put(6L,"ss");

        printMap(skipListMap);
        System.out.println("clear之后：");

        ConcurrentNavigableMap<Long, String> concurrentNavigableMap = skipListMap.headMap(4L, true);
        concurrentNavigableMap.clear();
        printMap(skipListMap);

    }

    public static void printMap(ConcurrentSkipListMap<Long, String> skipListMap){
        for (Map.Entry<Long, String> entry : skipListMap.entrySet()) {
            System.out.println("key = " + entry.getKey() + ", value = " + entry.getValue());
        }
    }
}
